﻿using System;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.Silverlight.Testing;
using Numbers;
using System8ToyMC;
using System.Windows.Controls;
using ObjectDirectory;

namespace t_System8ToyMCControls
{
    [TestClass]
    public class t_FlavorSampleUC : PresentationTest
    {
        FlavorSampleUC _val;
        FlavorSample _sample = new FlavorSample();

        [TestInitialize]
        public void TestSetup()
        {
            _val = new FlavorSampleUC();
            _val.FlavorInfo = _sample;
            TestPanel.Children.Add(_val);
        }

        [TestMethod]
        public void TestCtor()
        {
        }

        [TestMethod]
        public void TestName()
        {
            _val.SampleName = "eps 1234";
            TextBlock b = _val.FindName("TBName") as TextBlock;
            Assert.IsNotNull(b, "Can't get text block that matches the name");
            Assert.AreEqual("eps 1234", b.Text, "The name is not right!");
        }

        [TestMethod]
        public void TestSettingFS()
        {
            NamedValue nb = _val.FindName("NVnb") as NamedValue;
            NamedValue nc = _val.FindName("NVnc") as NamedValue;
            NamedValue nl = _val.FindName("NVnl") as NamedValue;
            NamedValue ncl = _val.FindName("NVncl") as NamedValue;
            NamedValue ntot = _val.FindName("NVntot") as NamedValue;

            Assert.IsNotNull(nb, "Could not find nb");
            Assert.IsNotNull(nc, "Could not find nc");
            Assert.IsNotNull(nl, "Could not find nl");
            Assert.IsNotNull(ncl, "Could not find ncl");
            Assert.IsNotNull(ntot, "Could not find ntot");

            _sample.Bottom = 100;
            _sample.Charm = 200;
            _sample.Light = 300;

            Assert.AreEqual(100.0, nb.Value, "nb is incorrect");
            Assert.AreEqual(200.0, nc.Value, "nc is incorrect");
            Assert.AreEqual(300.0, nl.Value, "nl is incorrect");
            Assert.AreEqual(500.0, ncl.Value, "ncl is incorrect");
            Assert.AreEqual(600.0, ntot.Value, "ntot is incorrect");

            _sample.Charm = 300;
            _sample.LightCharm = 800;
            Assert.AreEqual(400.0, nl.Value, "nl didn't get updated when we set cl");
        }

        [TestMethod]
        public void TestSettingValues()
        {
            NamedValue nb = _val.FindName("NVnb") as NamedValue;
            NamedValue nc = _val.FindName("NVnc") as NamedValue;
            NamedValue nl = _val.FindName("NVnl") as NamedValue;
            NamedValue ncl = _val.FindName("NVncl") as NamedValue;
            NamedValue ntot = _val.FindName("NVntot") as NamedValue;

            nb.Value = 100;
            nc.Value = 100;
            nl.Value = 100;

            Assert.AreEqual(100.0, _sample.Bottom, "Bottom is not been updated!");
            Assert.AreEqual(100.0, _sample.Light, "light has not been updated!");
            Assert.AreEqual(100.0, _sample.Charm, "Charm has not been updated!");

            ncl.Value = 50;
            Assert.AreEqual(50.0, _sample.LightCharm, "Light charm has not been updated!");

            ntot.Value = 100;
            Assert.AreEqual(100.0, _sample.Total, "Total has not been updated!");
        }

        public class FlavorHolder
        {
            public FlavorSample s { get; set; }
        }

        [TestMethod]
        public void TestPath()
        {
            NamedValue nb = _val.FindName("NVnb") as NamedValue;
            NamedValue nc = _val.FindName("NVnc") as NamedValue;
            NamedValue nl = _val.FindName("NVnl") as NamedValue;
            NamedValue ncl = _val.FindName("NVncl") as NamedValue;
            NamedValue ntot = _val.FindName("NVntot") as NamedValue;

            FlavorHolder fh = new FlavorHolder() { s = new FlavorSample() };
            ObjectPathManager mgr = new ObjectPathManager();

            _val.Path = "s";
            Assert.AreEqual("s", _val.Path, "Straight path not set right");
            Assert.AreEqual(mgr.GetPath(fh, fh.s.BottomValue), nb.Path, "n bottom path is not right");
            Assert.AreEqual(mgr.GetPath(fh, fh.s.CharmValue), nc.Path, "n bottom path is not right");
            Assert.AreEqual(mgr.GetPath(fh, fh.s.LightValue), nl.Path, "n bottom path is not right");
            Assert.AreEqual(mgr.GetPath(fh, fh.s.TotalValue), ntot.Path, "n bottom path is not right");
            Assert.AreEqual(mgr.GetPath(fh, fh.s.LightCharmValue), ncl.Path, "n bottom path is not right");
        }
    }
}